home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / SampleSMSAMServer / ConfigurationDBStuff.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  4.5 KB  |  206 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ConfigurationDBStuff.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifdef __BLJSTANDARDINCLUDES__
  15. #include "BLJStandardIncludes.h"
  16. #endif
  17.  
  18. #ifndef __DEBUGGINGGEAR__
  19. #include "DebuggingGear.h"
  20. #endif
  21.  
  22. #ifndef __MAILGATEWAY__
  23. #include "MailGateway.h"
  24. #endif
  25.  
  26. #ifndef    __DEBUGASSERT__
  27. #include "DebugAssert.h"
  28. #endif
  29.  
  30. #ifndef __TUPLEDATABASE__
  31. #include "TupleDatabase.h"
  32. #endif
  33.  
  34. #ifndef    __DEBUGCONSTANTS__
  35. #include "DebugConstants.h"
  36. #endif
  37.  
  38. #ifndef    __DEBUGSTREAM__
  39. #include "DebugStream.h"
  40. #endif
  41.  
  42. extern TMailGateway* gMailGateway;
  43.  
  44. extern void DumpHex ( ostream&, const void*, unsigned long );
  45.  
  46. /***********************************|****************************************/
  47.  
  48. #pragma segment ConfigDB
  49. void ShowConfigDB() 
  50. {
  51.     if (gMailGateway) 
  52.     {
  53.         keith << "Configuration Info:" << endl;
  54.         CTupleKey key;
  55.         CDataItem data;
  56.         
  57.         for ( short itemNum = 1; gMailGateway->GetNthConfigKey(itemNum, key); ++itemNum ) 
  58.         {
  59.             if ( gMailGateway->GetConfigItem(key, data) )
  60.             {
  61.                 keith << "key: " << key << "     " << data << endl;
  62.             }
  63.         }
  64.     }
  65.     else
  66.         SysBeep ( 10 );
  67. }
  68.  
  69. /***********************************|****************************************/
  70.  
  71. void ShowStatusDB() 
  72. {
  73.     keith << "Status Info: (Not Implemented)\n";
  74. }
  75.  
  76. /***********************************|****************************************/
  77.  
  78. Handle GetControlH(DialogPtr dialog, short index) 
  79. {
  80.     short    itemType;
  81.     Rect    itemRect;
  82.     Handle    itemHandle;
  83.     
  84.     GetDItem(dialog, index, &itemType, &itemHandle, &itemRect);
  85.     
  86.     return itemHandle;
  87. }
  88.  
  89. /***********************************|****************************************/
  90.  
  91. enum ConfigDialogControls
  92. {
  93.     kSetValue = 1,
  94.     kDeleteTuple,
  95.     kCancel,
  96.     kAttributeKeyText,
  97.     kAttributeValueText,
  98.     kPascalType,
  99.     kCType,
  100.     kRStringType,
  101.     kBooleanType,
  102.     kLongType,
  103.     kShortType,
  104.     kRawData
  105. };
  106.  
  107. void DoSetTupleDialog() 
  108. {
  109.     DialogPtr dialog;
  110.     short tupleType = kPascalType;
  111.     short itemHit;
  112.     
  113.     dialog = GetNewDialog(1000, nil, (WindowPtr) -1);
  114.  
  115.     ASSERT_RETURN ( dialog != nil );
  116.     
  117.     //    Set the default tuple type
  118.     SetCtlValue((ControlHandle) GetControlH(dialog, tupleType), 1);
  119.  
  120.     //    Handle the dialog
  121.     do {
  122.         ModalDialog(nil, &itemHit);
  123.     
  124.         switch (itemHit)
  125.         {
  126.             case kPascalType:
  127.             case kCType:
  128.             case kRStringType:
  129.             case kBooleanType:
  130.             case kLongType:
  131.             case kShortType:
  132.             case kRawData:
  133.                 tupleType = itemHit;
  134.                 SetCtlValue((ControlHandle) GetControlH(dialog, itemHit), 1);
  135.                 for (int index = kPascalType; index <= kRawData; ++index)
  136.                     if (index != itemHit)
  137.                         SetCtlValue((ControlHandle) GetControlH(dialog, index), 0);
  138.             break;    
  139.         }
  140.     } while ((itemHit != kSetValue) && (itemHit != kDeleteTuple) && (itemHit != kCancel));
  141.  
  142.     Str255 string;
  143.     GetIText ( GetControlH ( dialog, kAttributeKeyText ), string );
  144.     CTupleKey attributeKey ( string );
  145.     GetIText ( GetControlH ( dialog, kAttributeValueText ), string );
  146.     
  147.     if (itemHit == kSetValue) 
  148.     {    
  149.         switch (tupleType) 
  150.         {
  151.             case kPascalType:
  152.                 gMailGateway->SetConfigItem ( attributeKey, CDataItem ( string, string [ 0 ] + 1 ) );
  153.                 break;
  154.  
  155.             case kCType:
  156.                 string [ string [ 0 ] + 1 ] = 0;
  157.                 gMailGateway->SetConfigItem ( attributeKey, CDataItem ( string + 1, string [ 0 ] + 1 ) );
  158.             break;
  159.             
  160.             case kRStringType:
  161.             {
  162.                 CDataItem buffer ( sizeof ( RString ) );
  163.                 OCEPToRString ( string, smRoman, (RString*) buffer.GetPhysicalStart (), (unsigned short) buffer.GetPhysicalLength () );
  164.                 gMailGateway->SetConfigItem ( attributeKey, buffer );
  165.                 break;
  166.             }
  167.             
  168.             case kBooleanType:
  169.             {
  170.                 Boolean value = IUEqualString ( string, "\ptrue" ) == 0;
  171.                 gMailGateway->SetConfigItem ( attributeKey, CWrapperDataItem ( &value, sizeof ( value ), typeBoolean ) );
  172.                 break;
  173.             }
  174.             
  175.             case kLongType:
  176.             {    
  177.                 long value;
  178.                 StringToNum ( string, &value );
  179.                 gMailGateway->SetConfigItem ( attributeKey, CWrapperDataItem ( &value, sizeof ( value ), typeLongInteger ) );
  180.                 break;
  181.             }
  182.             
  183.             case kShortType:
  184.             {    
  185.                 long tempValue;
  186.                 StringToNum ( string, &tempValue );
  187.                 short value = (short) tempValue;
  188.                 gMailGateway->SetConfigItem ( attributeKey, CWrapperDataItem ( &value, sizeof ( value ), typeShortInteger ) );
  189.                 break;
  190.             }
  191.             
  192.             case kRawData:
  193.                 gMailGateway->SetConfigItem ( attributeKey, CWrapperDataItem ( string + 1, string [ 0 ], typeWildCard ) );
  194.                 break;
  195.         }
  196.     } 
  197.     else if (itemHit == kDeleteTuple) 
  198.     {
  199.         gMailGateway->DeleteConfigItem(attributeKey);
  200.     }
  201.  
  202.     DisposeDialog(dialog);
  203. }
  204.  
  205. /***********************************|****************************************/
  206.